//
//  LaundryTheOrderDetailsViewController.m
//  BaseFrame
//
//  Created by 吕金状 on 2017/8/17.
//  Copyright © 2017年 com.mxh. All rights reserved.
//

#import "LaundryTheOrderDetailsViewController.h"
#import "LaundryTheOrderDetailsTableViewCell.h"
#import "PrCodeView.h"
#import "LaundryTheOrderDetailsSecondTableViewCell.h"

@interface LaundryTheOrderDetailsViewController ()<UITableViewDataSource , UITableViewDelegate>

Strong UIView *headView;
Strong UILabel *titleLabel;
Strong UIView *footView;
Strong UITableView *tableView;
Strong NSMutableArray *dataArray; /**<*/
Strong UIImageView *titleImageView;
Strong UILabel *moneyLabel;
Strong UILabel *timeLabel;
Strong UILabel *theOrderNumber;
Strong UILabel *theOrderNumberLabel;
Strong NSMutableArray *dataSecondArray; /**<*/

@end

@implementation LaundryTheOrderDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"订单详情";
    [self.view addSubview:self.tableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



#pragma mark - <UITableViewDelegate , UITableViewDataSource>

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return self.dataArray.count;
    }
    return self.dataSecondArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        LaundryTheOrderDetailsTableViewCell *cell = [LaundryTheOrderDetailsTableViewCell cellForTableView:tableView];
        cell.indexPath = indexPath;
        cell.model = self.dataArray[indexPath.row];
        //cell.accessoryType = indexPath.row == 3 ?  UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
        return cell;
    }
    LaundryTheOrderDetailsSecondTableViewCell *cell = [LaundryTheOrderDetailsSecondTableViewCell cellForTableView:tableView];
    cell.indexPath = indexPath;
    cell.model = self.dataSecondArray[indexPath.row];
    //cell.accessoryType = indexPath.row == 3 ?  UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
    return cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 30 / WIDTH_5S_SCALE;
    }
    return 60 / WIDTH_5S_SCALE + 0.5;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 1 && indexPath.row == 0) {
        PrCodeView *view = [[PrCodeView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        view.nameString = @"asdsadasdada";
        [view show];
    }
}

#pragma mark - init

- (UILabel *)timeLabel{
    if (!_timeLabel) {
        _timeLabel  = [[UILabel alloc]init];
        _timeLabel.font = DEF_FontSize_14;
        _timeLabel.textColor = getColor(mainColor);
        _timeLabel.text = @"12:00:00";
    }
    return _timeLabel;
}

- (NSAttributedString *)getAttributeName{
    NSMutableAttributedString *attStr = [NSMutableAttributedString new];
    NSAttributedString *place = [[NSAttributedString alloc]initWithString:@"(倒计时为0则自动取消订单)" attributes:@{NSFontAttributeName:DEF_FontSize_12 , NSForegroundColorAttributeName:getColor(textColor)}];
    NSTextAttachment *seeAtt = [NSTextAttachment new];
    seeAtt.bounds = CGRectMake(0, -2 / WIDTH_5S_SCALE, 13 / WIDTH_5S_SCALE, 13 / WIDTH_5S_SCALE);
    seeAtt.image = [UIImage imageNamed:@"stateTime"];
    [attStr appendAttributedString:[NSAttributedString attributedStringWithAttachment:seeAtt]];
    [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"  %@",@"预约倒计时"]]];
    [attStr appendAttributedString:place];
    return attStr;
}

- (UIView *)headView{
    if (!_headView) {
        _headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 120 / WIDTH_5S_SCALE + 1.5)];
        UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 28 / WIDTH_5S_SCALE)];
        
        UILabel *leftLabel  = [[UILabel alloc]initWithFrame:CGRectMake(10 / WIDTH_5S_SCALE, 0, 300, 28 / WIDTH_5S_SCALE)];
        leftLabel.font = DEF_FontSize_14;
        leftLabel.textColor = getColor(mainColor);
        leftLabel.attributedText = [self getAttributeName];
        [bgView addSubview:leftLabel];
        [bgView addSubview:self.timeLabel];
        
        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 28 / WIDTH_5S_SCALE, SCREEN_WIDTH, 0.5)];
        lineView.backgroundColor = getColor(dividerColor);
        [_headView addSubview:lineView];
        
        UIView *line1View = [[UIView alloc]init];
        line1View.backgroundColor = getColor(dividerColor);
        
        UIView *line2View = [[UIView alloc]init];
        line2View.backgroundColor = getColor(dividerColor);
        
        UIView *line3View = [[UIView alloc]init];
        line3View.backgroundColor = getColor(dividerColor);
        
        UIView *line4View = [[UIView alloc]init];
        line4View.backgroundColor = getColor(dividerColor);
        
        [_headView sd_addSubviews:@[line1View , line2View , line3View , line4View , self.theOrderNumberLabel , self.theOrderNumber  , self.titleImageView , self.titleLabel , self.moneyLabel , bgView]];
        
        [self.titleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(10 / WIDTH_5S_SCALE);
            make.top.equalTo(lineView.mas_bottom).offset(10 / WIDTH_5S_SCALE);
            make.height.mas_equalTo(45 / WIDTH_5S_SCALE);
            make.width.mas_equalTo(45 / WIDTH_5S_SCALE);
        }];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.titleImageView.mas_right).offset(10 / WIDTH_5S_SCALE);
            make.top.equalTo(lineView.mas_bottom).offset(0 / WIDTH_5S_SCALE);
            make.height.mas_equalTo(65 / WIDTH_5S_SCALE);
        }];
        
        [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-10 / WIDTH_5S_SCALE);
            make.top.equalTo(lineView.mas_bottom).offset(0 / WIDTH_5S_SCALE);
            make.height.mas_equalTo(65 / WIDTH_5S_SCALE);
        }];
        
        [line1View mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(0 / WIDTH_5S_SCALE);
            make.right.mas_equalTo(0 / WIDTH_5S_SCALE);
            make.top.equalTo(self.titleLabel.mas_bottom).offset(0 / WIDTH_5S_SCALE);
            make.height.mas_equalTo(0.5);
        }];
        
        [self.theOrderNumber mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(10 / WIDTH_5S_SCALE);
            make.top.equalTo(line1View.mas_bottom).offset(0 / WIDTH_5S_SCALE);
            make.height.mas_equalTo(27 / WIDTH_5S_SCALE);
        }];
        
        [self.theOrderNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-10 / WIDTH_5S_SCALE);
            make.top.equalTo(line1View.mas_bottom).offset(0 / WIDTH_5S_SCALE);
            make.height.mas_equalTo(27 / WIDTH_5S_SCALE);
        }];
        
        [line2View mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(0 / WIDTH_5S_SCALE);
            make.right.mas_equalTo(0 / WIDTH_5S_SCALE);
            make.top.equalTo(self.theOrderNumber.mas_bottom).offset(0 / WIDTH_5S_SCALE);
            make.height.mas_equalTo(0.5);
        }];
        
    }
    return _headView;
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.sectionFooterHeight = .01;
        _tableView.sectionHeaderHeight = .01;
        _tableView.tableFooterView = self.footView;
        _tableView.tableHeaderView = self.headView;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.backgroundColor = getColor(@"ffffff");
    }
    return _tableView;
}


- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel  = [[UILabel alloc]init];
        _titleLabel.font = DEF_FontSize_14;
        _titleLabel.textColor = getColor(textColor);
        _titleLabel.numberOfLines = 0;
        _titleLabel.attributedText = [self getAttributeName:@"名称" info:@"25" money:@"299"];
    }
    return _titleLabel;
}

- (NSAttributedString *)getAttributeName:(NSString *)name info:(NSString *)info money:(NSString *)money{
    NSMutableAttributedString *attStr = [NSMutableAttributedString new];
    
    [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:name]];
    [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n"]];
    [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:@"数量  "]];
    [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:info]];
    [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n"]];
    [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:@"价格  ¥"]];
    [attStr appendAttributedString:[[NSAttributedString alloc] initWithString:money]];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:6];//调整行间距
    
    [attStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [attStr.mutableString length])];
    
    return attStr;
}

- (UIImageView *)titleImageView{
    if (!_titleImageView) {
        _titleImageView = [UIImageView new];
        _titleImageView.contentMode = UIViewContentModeScaleAspectFit;
        _titleImageView.backgroundColor = getColor(@"666666");
        _titleImageView.image = [UIImage imageNamed:@""];
    }
    return _titleImageView;
}

- (UILabel *)moneyLabel{
    if (!_moneyLabel) {
        _moneyLabel  = [[UILabel alloc]init];
        _moneyLabel.font = DEF_FontSize_14;
        _moneyLabel.textColor = getColor(mainColor);
        _moneyLabel.text = [NSString stringWithFormat:@"总价  ¥%@",@"36.00"];
    }
    return _moneyLabel;
}

- (UILabel *)theOrderNumber{
    if (!_theOrderNumber) {
        _theOrderNumber  = [[UILabel alloc]init];
        _theOrderNumber.font = DEF_FontSize_14;
        _theOrderNumber.textColor = getColor(textColor);
        NSMutableAttributedString *attStr1 = [NSMutableAttributedString new];
        NSTextAttachment *seeAtt1 = [NSTextAttachment new];
        seeAtt1.bounds = CGRectMake(0, -2 / WIDTH_5S_SCALE, 10 / WIDTH_5S_SCALE, 13 / WIDTH_5S_SCALE);
        seeAtt1.image = [UIImage imageNamed:@"root_TheOrderNumber"];
        [attStr1 appendAttributedString:[NSAttributedString attributedStringWithAttachment:seeAtt1]];
        [attStr1 appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"  %@",@"订单号"]]];
        _theOrderNumber.attributedText = attStr1;
    }
    return _theOrderNumber;
}

- (UILabel *)theOrderNumberLabel{
    if (!_theOrderNumberLabel) {
        _theOrderNumberLabel  = [[UILabel alloc]init];
        _theOrderNumberLabel.font = DEF_FontSize_14;
        _theOrderNumberLabel.textColor = getColor(textColor);
        _theOrderNumberLabel.textAlignment = NSTextAlignmentRight;
        _theOrderNumberLabel.text = @"3253454213123";
    }
    return _theOrderNumberLabel;
}

#pragma mark - data

- (NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray  = @[@{@"title":@"已下单",@"time":@"2017-08-08 12:22:33"}.mutableCopy,
                        @{@"title":@"已下单",@"time":@"2017-08-08 12:22:33"}.mutableCopy,@{@"title":@"已下单",@"time":@"2017-08-08 12:22:33"}.mutableCopy,@{@"title":@"已下单",@"time":@"2017-08-08 12:22:33"}.mutableCopy,@{@"title":@"已下单",@"time":@"2017-08-08 12:22:33"}.mutableCopy,
                        ].mutableCopy;
    }
    return _dataArray;
}

- (NSMutableArray *)dataSecondArray{
    if (!_dataSecondArray) {
        _dataSecondArray  = @[
                              @{@"image":@"prCode",@"title":@"取件二维码",@"content":@"点击查看"},
                              
                              @{@"image":@"TakeThePassword",@"title":@"取件口令",@"content":@"XXXXXXXXXXXXXXXXXXXXX"},
                              @{@"image":@"address",@"title":@"预约柜位置",@"content":@"地址信息地址信息地址信息地址信息地址信息"},
                              @{@"image":@"root_IWantToLeaveAMessage",@"title":@"我的留言",@"content":@"地址信息地址信息地址信息地址信息地址信息"},
                        
                        ].mutableCopy;
    }
    return _dataSecondArray;
}


@end
